package com.shujia.flink.tf;

import org.apache.flink.api.common.typeinfo.Types;
import org.apache.flink.streaming.api.datastream.DataStreamSource;
import org.apache.flink.streaming.api.environment.StreamExecutionEnvironment;

public class Demo03FlatMap {
    public static void main(String[] args) throws Exception {
        /*
         * flatMap算子：传入一行返回N行
         */
        StreamExecutionEnvironment env = StreamExecutionEnvironment.getExecutionEnvironment();

        DataStreamSource<String> socketDS = env.socketTextStream("master", 8888);

        // 将过来的数据切开来，并逐条发送到下游
        socketDS.flatMap((line, out) -> {
            for (String word : line.split(",| ")) {
                out.collect(word);
            }
        }, Types.STRING).print();

        env.execute();
    }
}
